import constant from "@/utils/constant.js"

let storageKey = "storage_data"

let storageNodeKeys = [constant.name,constant.avatar,constant.roles,constant.permissions]

const storage = {
	set(key,value){
		if(storageKey.indexOf(key)!=-1){
			//拿到这个缓存的对象
			let tmp = uni.getStorageSync(storageKey)
			tmp = tmp?tmp:{},
			//把缓存的这个对象的key的值更改为value
			tmp[key] = value
			//重新设置进缓存
			uni.setStorageSync(storageKey,tmp)
		}
	},
	get(key){
		let storageData = uni.getStorageSync(storageKey) || {}
		return storageData[key] || ""
	},
	remove(key){
		let storageData = uni.getStorageSync(storageKey) || {}
		delete storageData[key]
		uni.setStorageSync(storageKey,storageData)
	},
	clear(){
		uni.removeStorageSync(storageKey)
	}
}

export default storage